﻿using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using Teigha.Core;

namespace Teigha.TD
{
	public class OdDbLongTransaction : OdDbObject
	{
		[EditorBrowsable(EditorBrowsableState.Never)]
		public OdDbLongTransaction(IntPtr cPtr, bool cMemoryOwn) : base(TD_DbPINVOKE.OdDbLongTransaction_SWIGUpcast(cPtr), cMemoryOwn)
		{
			this.swigCPtr = new HandleRef(this, cPtr);
		}

		[EditorBrowsable(EditorBrowsableState.Never)]
		public static HandleRef getCPtr(OdDbLongTransaction obj)
		{
			if (obj != null)
			{
				return obj.swigCPtr;
			}
			return new HandleRef(null, IntPtr.Zero);
		}

		~OdDbLongTransaction()
		{
			this.Dispose();
		}

		public override void Dispose()
		{
			if (this.swigCPtr.Handle != IntPtr.Zero)
			{
				if (this.swigCMemOwn)
				{
					lock (this.locker)
					{
						if (this.swigCPtr.Handle != IntPtr.Zero && this.swigCMemOwn)
						{
							this.swigCMemOwn = false;
							TD_DbPINVOKE.delete_OdDbLongTransaction(this.swigCPtr);
						}
					}
					this.swigCMemOwn = false;
				}
				this.swigCPtr = new HandleRef(null, IntPtr.Zero);
			}
			GC.SuppressFinalize(this);
			base.Dispose();
		}

		public new static OdDbLongTransaction cast(OdRxObject pObj)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbLongTransaction_cast(OdRxObject.getCPtr(pObj));
			OdDbLongTransaction result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdDbLongTransaction)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdDbLongTransaction)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdDbLongTransaction)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new static OdRxClass desc()
		{
			OdRxClass result = (OdRxClass)Teigha.Core.Helpers.odrxCreateObjectInternal(TD_DbPINVOKE.OdDbLongTransaction_desc(), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new virtual OdRxClass isA()
		{
			OdRxClass result = (OdRxClass)Teigha.Core.Helpers.odrxCreateObjectInternal(TD_DbPINVOKE.OdDbLongTransaction_isA(this.swigCPtr), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new virtual OdRxObject queryX(OdRxClass protocolClass)
		{
			OdRxObject result = Teigha.Core.Helpers.odrxCreateObjectInternal(TD_DbPINVOKE.OdDbLongTransaction_queryX(this.swigCPtr, OdRxClass.getCPtr(protocolClass)), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new static OdDbLongTransaction createObject()
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbLongTransaction_createObject();
			OdDbLongTransaction result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdDbLongTransaction)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdDbLongTransaction)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdDbLongTransaction)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public int type()
		{
			int result = TD_DbPINVOKE.OdDbLongTransaction_type(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdDbObjectId originBlock()
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr cPtr = TD_DbPINVOKE.OdDbLongTransaction_originBlock(this.swigCPtr);
			OdDbObjectId result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject(new OdDbObjectId(cPtr, true));
				result = new OdDbObjectId(cPtr, false);
			}
			else
			{
				result = new OdDbObjectId(cPtr, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdDbObjectId destinationBlock()
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr cPtr = TD_DbPINVOKE.OdDbLongTransaction_destinationBlock(this.swigCPtr);
			OdDbObjectId result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject(new OdDbObjectId(cPtr, true));
				result = new OdDbObjectId(cPtr, false);
			}
			else
			{
				result = new OdDbObjectId(cPtr, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public string getLongTransactionName()
		{
			string result = TD_DbPINVOKE.OdDbLongTransaction_getLongTransactionName(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdResult addToWorkSet(OdDbObjectId ObjectId)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbLongTransaction_addToWorkSet(this.swigCPtr, OdDbObjectId.getCPtr(ObjectId));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdResult removeFromWorkSet(OdDbObjectId id)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbLongTransaction_removeFromWorkSet(this.swigCPtr, OdDbObjectId.getCPtr(id));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdResult syncWorkSet()
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbLongTransaction_syncWorkSet(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdDbLongTransWorkSetIterator newWorkSetIterator(bool incRemovedObjs, bool incSecondaryObjs)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbLongTransaction_newWorkSetIterator__SWIG_0(this.swigCPtr, incRemovedObjs, incSecondaryObjs);
			OdDbLongTransWorkSetIterator result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdDbLongTransWorkSetIterator)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdDbLongTransWorkSetIterator)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdDbLongTransWorkSetIterator)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdDbLongTransWorkSetIterator newWorkSetIterator(bool incRemovedObjs)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbLongTransaction_newWorkSetIterator__SWIG_1(this.swigCPtr, incRemovedObjs);
			OdDbLongTransWorkSetIterator result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdDbLongTransWorkSetIterator)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdDbLongTransWorkSetIterator)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdDbLongTransWorkSetIterator)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdDbLongTransWorkSetIterator newWorkSetIterator()
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbLongTransaction_newWorkSetIterator__SWIG_2(this.swigCPtr);
			OdDbLongTransWorkSetIterator result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdDbLongTransWorkSetIterator)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdDbLongTransWorkSetIterator)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdDbLongTransWorkSetIterator)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdDbObjectId originObject(OdDbObjectId workSetId)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr cPtr = TD_DbPINVOKE.OdDbLongTransaction_originObject(this.swigCPtr, OdDbObjectId.getCPtr(workSetId));
			OdDbObjectId result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject(new OdDbObjectId(cPtr, true));
				result = new OdDbObjectId(cPtr, false);
			}
			else
			{
				result = new OdDbObjectId(cPtr, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public bool workSetHas(OdDbObjectId ObjectId, bool getErased)
		{
			bool result = TD_DbPINVOKE.OdDbLongTransaction_workSetHas__SWIG_0(this.swigCPtr, OdDbObjectId.getCPtr(ObjectId), getErased);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public bool workSetHas(OdDbObjectId ObjectId)
		{
			bool result = TD_DbPINVOKE.OdDbLongTransaction_workSetHas__SWIG_1(this.swigCPtr, OdDbObjectId.getCPtr(ObjectId));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdDbIdMapping activeIdMap()
		{
			OdDbIdMapping result = (OdDbIdMapping)Teigha.Core.Helpers.odrxCreateObjectInternal(TD_DbPINVOKE.OdDbLongTransaction_activeIdMap(this.swigCPtr), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new virtual void applyPartialUndo(OdDbDwgFiler pUndoFiler, OdRxClass pClassObj)
		{
			TD_DbPINVOKE.OdDbLongTransaction_applyPartialUndo(this.swigCPtr, OdDbDwgFiler.getCPtr(pUndoFiler), OdRxClass.getCPtr(pClassObj));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public new virtual OdResult dwgInFields(OdDbDwgFiler pFiler)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbLongTransaction_dwgInFields(this.swigCPtr, OdDbDwgFiler.getCPtr(pFiler));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new virtual void dwgOutFields(OdDbDwgFiler pFiler)
		{
			TD_DbPINVOKE.OdDbLongTransaction_dwgOutFields(this.swigCPtr, OdDbDwgFiler.getCPtr(pFiler));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public new virtual OdResult subErase(bool erasing)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbLongTransaction_subErase(this.swigCPtr, erasing);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public const int kSameDb = 0;

		public const int kXrefDb = 1;

		public const int kUnrelatedDb = 2;

		private object locker = new object();

		private HandleRef swigCPtr;
	}
}
